<template>
  <view class="news-item">
    <view class="news-content">
      <text class="news-subtitle">{{ subtitle }}</text>
      <view class="news-meta">
        <text>发布时间：{{ publishDate }}</text>
        <text class="source">来源：{{ source }}</text>
      </view>
    </view>
    <view class="image-container">
      <image :src="imageSrc" mode="aspectFill" @load="onImageLoad" @error="onImageError"></image>
    </view>
  </view>
</template>

<script setup>
import { defineProps, ref } from 'vue';

const props = defineProps({
  subtitle: {
    type: String,
    default: ''
  },
  publishDate: {
    type: String,
    default: ''
  },
  source: {
    type: String,
    default: ''
  },
  imageSrc: {
    type: String,
    default: ''
  }
});

const imageLoaded = ref(false);

const onImageLoad = () => {
  imageLoaded.value = true;
  console.log('图片加载成功');
};

const onImageError = (e) => {
  console.error('图片加载失败:', e);
};
</script>

<style scoped lang='scss'>
.news-item {
  display: flex;
  padding: 40rpx 0;
  align-items: center;

  .news-content {
    flex: 1;
    .news-subtitle {
      font-size: 36rpx;
      color: #333;
      font-weight: bold;
      margin-bottom: 16rpx;
    }

    .news-meta {
      margin-top: 30rpx;
      width: 300rpx;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      font-size: 28rpx;
      color: #999;
    }
  }

  .image-container {
    width: 160rpx;
    height: 160rpx;
    border-radius: 8rpx;
    overflow: hidden;
    margin-left: 60rpx;
  }

  image {
    width: 100%;
    height: 100%;
    transition: opacity 0.3s;
    opacity: 0;
    &[loaded] {
      opacity: 1;
    }
  }
}
</style>
